var prefix = jsctx + "/tenantChargeLog";

var orderTracel = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        },10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    function load() {
        getEchars()
    };

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
        getEchars()
    };

    //获取数据
    function getEchars() {
        var myChart = echarts.init(document.getElementById('main'));
        myChart.showLoading();
        $.ajax({
            "url": prefix + "/listChargeProcessLog",
            "method": "GET",
            "data": {
                limit: 1000,
                offset: 0,
                operatorId: $('#searchOperatorId').val(),
                orderNum: $("#searchOrderNum").val(),
                outOrderNum: $("#searchOutOrderNum").val(),
                queryTime: $("#queryTime").val()
            },
            "success": function (data) {
                myChart.hideLoading();
                d(data, myChart);

            }
        })
    }

    function d(data, myChart) {
        // 基于准备好的dom，初始化echarts实例
        myChart.setOption({
            title: {
                text: '订单结算轨迹',
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            toolbox: {
                feature: {
                    // dataView: {show: true, readOnly: false},
                    // magicType: {show: true, type: ['line', 'bar']},
                    // restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            legend: {
                data: ['SOC', '总电量', '电压', '电流']
            },
            xAxis: [
                {
                    type: 'category',
                    data: data.rows.map(function (ele) {
                        return ele.createTime;
                    }),
                    axisPointer: {
                        type: 'shadow'
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                }
            ],
            series: [
                {
                    name: 'soc',
                    type: 'line',
                    data: data.rows.map(function (ele) {
                        return ele.soc;
                    }),
                },
                {
                    name: '总电量',
                    type: 'line',
                    data: data.rows.map(function (ele) {
                        return ele.power;
                    }),
                },
                {
                    name: '电压',
                    type: 'line',
                    data: data.rows.map(function (ele) {
                        return ele.voltage;
                    }),
                },
                {
                    name: '电流',
                    type: 'line',
                    data: data.rows.map(function (ele) {
                        return ele.elec;
                    }),
                }
            ]
        })
    };

    return {
        init: init,
        reLoad: reLoad
    };
})();

